﻿package src.states{
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import src.game.managers.SoundManager;
	import src.sound.SoundPlayer;
	
	public class EndGame extends GameState{
		private var endGameMC:EndGameMc;
		public function EndGame(display:DisplayObjectContainer, gameStates:GameStatesMachine) {
			super(display, gameStates);
		}
		
		public override function init():void {
			super.init();
			endGameMC = new EndGameMc();
			endGameMC.addEventListener(Event.COMPLETE, disposeEvent);
			displayContent.addChild(endGameMC);
			playSound();
		}
		
		private function playSound():void {
			var sm:SoundManager = SoundManager.getInstance();
			sm.add(new SoundPlayer(new GameOver()));
		}
		
		public override function update():void {
			super.update();
		}
		
		private function disposeEvent(event:Event):void {
			trace ("caputred event repeat");
			gameStates.resetAllStates();
			gameStates.setCurrentState(gameStates.getNewLevelState());
		}
		
		public override function dispose():void {
			super.dispose();
			displayContent.removeChild(endGameMC);
			endGameMC.removeEventListener(Event.COMPLETE, disposeEvent);
			endGameMC = null;
			//stage.focus = displayContent.stage;
		}
		
		
	}
}